<?php

/**
 * File that automatically deletet after execution end
 */
class TemporaryFile {

    private $path;

    public function __construct($type = '') {
        $this->path = Env::getTmpDir() .  time() . '-' . mt_rand(0,1000) . '.tmp' . ($type ? '.' . $type : '');
        register_shutdown_function(array($this, 'forceDelete'));
    }

    public function getPath() {
        return $this->path;
    }

    public function forceDelete() {
        if (!file_exists($this->path)) return;
        unlink($this->path);
    }

    public function append($str) {
        File::append($this->path, $str);
    }

    public function save($str) {
        File::save($this->path, $str);
    }

    public function load() {
        File::load($this->path);
    }
}

?>